$(function () {

    layui.use(['jquery', 'layer'], function () {
        var $ = layui.$ //重点处
            , layer = layui.layer;
    });


    $(".cb input").click(function () {
        alert(3);
        if ($(this).val() != 1) {
            alert(0);
        }else {
            alert(1);
        }
    });




    var index = 0;
    $.ajax({
        type: "GET",
        url: "/discountLevel/list",
        //dataType: "josn",
        success: function (data) {
            $.each(data.rows, function () {
                var div = $("#mydiv > div:first").clone(true);
                $("#mydiv > div:last").after(div);
                $(".myid").last().prop("name", "entitys[" + index + "].id").val(data.rows[index].id);
                $(".mymin").last().prop("name", "entitys[" + index + "].mintotalpoint").val(data.rows[index].mintotalpoint);
                $(".mymax").last().prop("name", "entitys[" + index + "].maxtotalpoint").val(data.rows[index].maxtotalpoint);
                $(".mydis").last().prop("name", "entitys[" + index + "].discount").val(data.rows[index].discount);
                $(".mylevel").last().prop("name", "entitys[" + index + "].levelName").val(data.rows[index].levelName);
                $(".mydelete").last().prop("name", index);
                index = index + 1;
            });
            $("#mydiv > div:first").remove();
        }
    });


    $(".myadd").click(function () {
        var div = $("#mydiv > div:first").clone(true);
        $("#mydiv > div:last").after(div);
        index = index + 1;
        $(".myid").last().prop("name", "entitys[" + index + "].id").val("");
        $(".mymin").last().prop("name", "entitys[" + index + "].mintotalpoint").val("");
        $(".mymax").last().prop("name", "entitys[" + index + "].maxtotalpoint").val("");
        $(".mydis").last().prop("name", "entitys[" + index + "].discount").val("");
        $(".mylevel").last().prop("name", "entitys[" + index + "].levelName").val("");
        $(".mydelete").last().prop("name", index);
    });

    $(".mydelete").click(function () {
        var deleId = $(this).attr("name");
        var deleteId = $("input[name='entitys[" + deleId + "].id']");
        $.get("/discountLevel/delete?id=" + deleteId.val(), function (data) {
            /*
            if (data.success) {
             layer.open({
             title: '温馨提示',
             content: '删除成功',
             yes: function (index, layero) {
             layer.close(index); //如果设定了yes回调，需进行手工关闭
             window.location.onload()
             }
             });
             } else {
             layer.open({
             title: '温馨提示',
             content: data.errorMsg,
             yes: function (index, layero) {
             layer.close(index); //如果设定了yes回调，需进行手工关闭
             top.window.location.onload()
             }
             });
             }*/
        });

    });
    $(".mymodelbtn").click(function () {
        layer.open({
            type: 2,
            title: "短信模版",
            shadeClose: true,
            shade: 0.8,
            area: ['60%', '60%'],
            content: '/discountLevel/message', //iframe的url
            btn: ['模版一', '模版二', "模版三", "模版四", "关闭"],
            btn1: function (index) {
                $.get("/dataItems/queryItemsBySn?sn=message", function (data) {
                    $(".myblock").text(data[0].intro)
                });
                //最后关闭弹出层
                layer.close(index);
            },
            btn2: function (index, layero) {
                $.get("/dataItems/queryItemsBySn?sn=message", function (data) {
                    $(".myblock").text(data[1].intro)
                });
                //最后关闭弹出层
                layer.close(index);

            },
            btn3: function (index, layero) {
                $.get("/dataItems/queryItemsBySn?sn=message", function (data) {
                    $(".myblock").text(data[2].intro)
                });
                //最后关闭弹出层
                layer.close(index);

            },
            btn4: function (index, layero) {
                $.get("/dataItems/queryItemsBySn?sn=message", function (data) {
                    $(".myblock").text(data[3].intro)
                });
                //最后关闭弹出层
                layer.close(index);

            },
            cancel: function () {
                //右上角关闭回调
            }
        });
    });

    $("button[type='reset']").click(function () {
        $(".myblock").text("")
    });

});